package com.qyhl.webtv.module_live.teletext.nanbu.fragment;

import android.util.Log;

import com.qyhl.webtv.basiclib.utils.network.EasyHttp;
import com.qyhl.webtv.basiclib.utils.network.callback.SimpleCallBack;
import com.qyhl.webtv.basiclib.utils.network.exception.ApiException;
import com.qyhl.webtv.commonlib.common.CommonUtils;
import com.qyhl.webtv.commonlib.entity.live.TeleTextBean;
import com.qyhl.webtv.module_live.common.LiveUrl;

import java.util.List;

public class NanBuLiveModel implements NanBuLiveContract.NanBuLiveModel {
    private NanBuLivePresenter mPresenter;

    public NanBuLiveModel(NanBuLivePresenter mPresenter) {
        this.mPresenter = mPresenter;
    }

    @Override
    public void getList(String tagId, String sceneId) {
        EasyHttp.get(LiveUrl.GET_TELETEXT_LIST)
                .params("siteId", CommonUtils.getInstance().getSite() + "")
                .params("sceneId", sceneId)
                .params("tag", tagId)
                .params("type", "0")
                .execute(new SimpleCallBack<List<TeleTextBean>>() {
                    @Override
                    public void onError(ApiException e) {
                        if (e.getCode() == 202) {
                            mPresenter.setError("暂无任何内容！", !sceneId.equals("0"));
                        } else {
                            mPresenter.setError("请求出错，请重新获取！", !sceneId.equals("0"));
                        }
                    }

                    @Override
                    public void onSuccess(List<TeleTextBean> teleTextBeans) {
                        if (teleTextBeans != null && teleTextBeans.size() > 0) {
                            mPresenter.setData(teleTextBeans, !sceneId.equals("0"));
                        } else {
                            mPresenter.setError("暂无任何内容！", !sceneId.equals("0"));
                        }
                    }
                });
    }
}
